﻿#include <QCoreApplication>
#include <QDateTime>
#include "commonfuc.h"

#ifndef NO_WIDGETS
QWidget* CommonFuc::m_pTopWidget = NULL;
#endif

CommonFuc::CommonFuc()
{

}

#ifndef NO_WIDGETS
void CommonFuc::messageBox(const QString &text,QString title/* = "tips"*/)
{
    QMessageBox::information(m_pTopWidget,title,text);
    return;
}
#endif

QString CommonFuc::getAppDirPath()
{
    QString strPath = QCoreApplication::applicationDirPath();
    strPath.append("/");

    return strPath;
}

QString CommonFuc::getCurTime()
{
    QDateTime datetime =  QDateTime::currentDateTime();
    QString strTime;
    strTime.sprintf("%04d-%02d-%02d %02d:%02d:%02d",datetime.date().year(),
    datetime.date().month(),datetime.date().day(),datetime.time().hour(),
    datetime.time().minute(),datetime.time().second());

    return strTime;
}

void CommonFuc::GetCharByQString(QString &str,char* des,int len)
{
   //QTextCodec::codecForName("utf-8");//GBK

    //test
    /*QString strTest = "dcfab好事吗123dda";
    QByteArray ba = strTest.toLatin1();
    const char* p = ba.data();
    ba = strTest.toUtf8();
    const char* p1 = ba.data();*/


    //std::string str = strText.toStdString();
    //return str.c_str();

    //QByteArray ba = strText.toUtf8();
    //return ba.data();

    if(NULL==des)
    {
        return;
    }

// 	memset(des,0,len);
// 	QByteArray ba = str.toLatin1();
// 	strncpy(des,ba.data(),ba.length());

//	memset(des,0,len);
//	QByteArray ba1 = str.toAscii();
//	strncpy(des,ba1.data(),ba1.length());

    memset(des,0,len);
    QByteArray ba2 = str.toUtf8();
    strncpy(des,ba2.data(),ba2.length());

    /*memset(des,0,len);
    QByteArray ba3 = str.toLocal8Bit();
    strncpy(des,ba3.data(),ba3.length());*/

}

QString  CommonFuc::GetBase64Encode(QString & in)
{
    QByteArray  tmp_in (in.toUtf8());
    return QString(tmp_in.toBase64());
}


